package com.player.rest.resource;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.json.JSONException;

import com.player.dao.DAOLocator;
import com.player.entity.Ranking;
import com.player.entity.RankinglistType;
import com.player.rest.util.ResponseConverter;

@Path("rankings")
public class RankingResource {

	@GET
	@Path("{rankinglistType}")
	@Produces(MediaType.APPLICATION_JSON)
	public String getRankings(@PathParam("rankinglistType") String rankinglistType) throws JSONException {
		RankinglistType rankinglist = RankinglistType.valueOf(rankinglistType);
		List<Ranking> rankings = DAOLocator.getRankingDAO().getAllWithPlayers(rankinglist);
		return ResponseConverter.toJSONRanking(rankings, rankinglist);
	}

}
